require"lfs"

local BLP2PNG = "c:\\Tools\\BLP2PNG.exe"
local SRC_PATH = "E:\\Jeux (x86)\\World of Warcraft\\Blizzard Interface Art (enGB)"
local DST_PATH = "Interface"
local SEP = "\\"

local function execute(s)
--~ 	print(s)
	os.execute(s)
end

local function convert(src, dstpath)
	execute(string.format("%s \"%s\"", BLP2PNG, src))
	execute(string.format("move \"%s\" \"%s\" > NUL 2> NUL", src:gsub("%.[Bb][Ll][Pp]$", ".png"), dstpath))
end

local function convert_path(src, dst)
	for file in lfs.dir(src) do
		if file ~= "." and file ~= ".." then
			local sfile = src..SEP..file
			local attr = lfs.attributes(sfile)
			local mode = attr and attr.mode
			if mode == "directory" then
				local dpath = dst..SEP..file
				lfs.mkdir(dpath)
				convert_path(sfile, dpath)
			elseif mode == "file" and file:find("%.[Bb][Ll][Pp]$") then
				convert(sfile, dst)
			else
				print("error", mode, sfile)
			end
		end
	end
end

convert_path(SRC_PATH, DST_PATH)
